﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DTO;
using BUS;

namespace Project.module
{
    public partial class frmThemban : Form
    {
        private int makv = 0;
        public class ComboboxItem
        {
            public string Text { get; set; }
            public int Value { get; set; }

            public override string ToString()
            {
                return Text;
            }
        }
        public frmThemban()
        {
            InitializeComponent();
        }

        private void frmThemban_Load(object sender, EventArgs e)
        {
            makv = (int)this.Tag;
            List<KhuVucDTO> lstKV = KhuVucBUS.Listkhuvuc();
            if (lstKV.Count > 0)
            {
                foreach (KhuVucDTO kv in lstKV)
                {
                    ComboboxItem it = new ComboboxItem();
                    it.Text = kv.Tenkv;
                    it.Value = kv.Makv;


                    cbKhuvuc.Items.Add(it);
                }
                cbKhuvuc.SelectedText = KhuVucBUS.GetTenKV(makv);
            }
        }

        private void bntThem_Click(object sender, EventArgs e)
        {
            BanDTO ban = new BanDTO();
            ban.Makv = makv;
            ban.Succhua = int.Parse(txtSucchua.Text);
            ban.Trangthai = 0;
            bool kt = BanBUS.Themban(ban);
            if (kt == true)
            {
                
                this.Close();
            }
            else
            {
                MessageBox.Show("Không thành công ! Lỗi thêm bàn !");
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
